package camid.util.dataanalysis;

import java.util.ArrayList;
import java.util.List;

public class DataMetric {
	
	private List<Double> downtimes;
	
	private Integer numberObjects;
	
	private Integer serviceTime;
	
	public DataMetric(Integer numberObjects, Integer serviceTime) 
	{
		downtimes = new ArrayList<Double>();
		this.numberObjects = numberObjects;
		this.serviceTime = serviceTime;
	}

	public List<Double> getDowntimes() {
		return downtimes;
	}

	public void setDowntimes(List<Double> downtimes) {
		this.downtimes = downtimes;
	}

	public Integer getNumberObjects() {
		return numberObjects;
	}

	public void setNumberObjects(Integer numberObjects) {
		this.numberObjects = numberObjects;
	}

	public Integer getServiceTime() {
		return serviceTime;
	}

	public void setServiceTime(Integer serviceTime) {
		this.serviceTime = serviceTime;
	}
	
	public static String getKey(Integer numberObjects, Integer serviceTime)
	{
		return numberObjects + "#" + serviceTime;
	}

	private Double avg;
	private Double stddev;
	
	public void evaluate()
	{
		avg = 0.0;
		for(Double d : downtimes)
		{
			avg += d;
		}
		avg /= downtimes.size();
		stddev = 0.0;
		for(Double d : downtimes)
		{
			stddev += Math.pow((d - avg), 2);
		}
		stddev /= downtimes.size();
		stddev = Math.sqrt(stddev);
	}
	
	public Object getAverage() 
	{	
		return avg;
	}

	public Object getStddev() 
	{	
		return stddev;
	}

}
